package com.lastproject.ejb.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQuery(name = "QuestionOption.findAll", query = "SELECT qo FROM QuestionOption qo")
public class QuestionOption implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private int id;

	//uni directional
	@ManyToOne
	@JoinColumn(name = "idQuestion")
	private Question question;

	private String text;

	private String textDefault;

	private String type;

	@OneToMany(mappedBy = "questionOption")
	private List<Answer> answers;

	public QuestionOption() {
		super();
		// TODO Auto-generated constructor stub
	}

	public QuestionOption(int id, Question question, String text,
			String textDefault, String type, List<Answer> answers) {
		super();
		this.id = id;
		this.question = question;
		this.text = text;
		this.textDefault = textDefault;
		this.type = type;
		this.answers = answers;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Question getQuestion() {
		return question;
	}

	public void setQuestion(Question question) {
		this.question = question;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getTextDefault() {
		return textDefault;
	}

	public void setTextDefault(String textDefault) {
		this.textDefault = textDefault;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result
				+ ((question == null) ? 0 : question.hashCode());
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		result = prime * result
				+ ((textDefault == null) ? 0 : textDefault.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		QuestionOption other = (QuestionOption) obj;
		if (id != other.id)
			return false;
		if (question == null) {
			if (other.question != null)
				return false;
		} else if (!question.equals(other.question))
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		if (textDefault == null) {
			if (other.textDefault != null)
				return false;
		} else if (!textDefault.equals(other.textDefault))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "QuestionOption [id=" + id + ", question=" + question
				+ ", text=" + text + ", textDefault=" + textDefault + ", type="
				+ type + ", answers=" + "]";
	}
	
	

}
